Ext.define('DragonApp.view.level.Grid', {
    extend: 'Ext.grid.Panel',

    alias: ['widget.level-grid'],

    requires: [
        'DragonApp.store.JsonPLevel',
        'Ext.overrides.grid.ExportGrid'
    ],

    collapsed : false,
    collapsible : true,

    controller: 'level',

    features: [{
        ftype: 'summary'
    }],

    tbar: [{
        text: '导出数据',
        iconCls: 'x-fa fa-file-excel-o',
        width: 120,
        handler: function(button) {
            var grid = button.up('grid');
            var includeHiddenColumns = true;
            var title = '游戏等级流失数据';
            grid.downloadExcelXml(includeHiddenColumns, title);
        }
    }],

    columns: [
        { text: '序号', xtype: 'rownumberer', width: 70,
            summaryType: 'max',
            summaryRenderer: function (value, summaryData, dataIndex){
            return ('合计');
            },
        align: 'center' },
        { text: '渠道', dataIndex: 'channel', renderer: 'channelRender', width: 120, align: 'center' },
        { text: '服务器', dataIndex: 'server', renderer: 'serverRender', width: 120, align: 'center' },
        {
            text: '等级',
            dataIndex: 'level',
            width: 100,
            align: 'center'
        },
        {
            text: '分布人数',
            dataIndex: 'total',
            width: 100,
            summaryType: 'sum',
            summaryRenderer: function (value, summaryData, dataIndex){
            return (value);
            },
            align: 'center' },
        {
            text: '（7日）活跃人数',
            dataIndex: 'active',
            width: 120,
            summaryType: 'sum',
            summaryRenderer: function (value, summaryData, dataIndex){
            return (value);
            },
            align: 'center' },
        {
            text: '流失人数',
            dataIndex: 'inactive',
            width: 100,
            summaryType: 'sum',
            summaryRenderer: function (value, summaryData, dataIndex){
            return (value);
            },
            align: 'center' },
        {
            text: '流失率',
            dataIndex: 'inactive_rate',
            flex: 1,
            summaryType: 'sum',
            summaryRenderer: function (value, summaryData, dataIndex, r){
                var tmpArr = Ext.Object.getValues(summaryData);
                    return ( 0 === tmpArr[4] ) ? '0.00%' : (Ext.util.Format.number((tmpArr[6]/tmpArr[4])*100, '0.00%'));
            },
            align: 'center'
        }
        //{ text: '基准流失', dataIndex: 'decorations', width: 100, align: 'center' }
    ],
    store: {
        type: 'jsonPLevelStore',
        storeId : 'jsonPLevelStore'
    }
});